﻿//using System;
//using System.Collections.Generic;
//using System.Text;
//using ZMQ;
//using NetSockets;
//using System.Net;

//namespace DCRF.Common.Distribution
//{

//    public class SimpleSocket: ISimpleSocket
//    {
//        private bool isServer = false;
//        private NetServer server = null;
//        private NetClient client = null;

//        public event OnDataReceivedDelegate DataReceived;
        
//        public SimpleSocket(bool bserver, object owner)
//        {
//            isServer = bserver;

//            if (isServer)
//            {
//                server = new NetServer();
//                server.owner = owner;
//                server.OnReceived += new NetClientReceivedEventHandler<byte[]>(server_OnReceived);
//            }
//            else
//            {
//                client = new NetClient();
//                client.owner = owner;
//                client.OnReceived += new NetReceivedEventHandler<byte[]>(client_OnReceived);
//            }
//        }

//        void client_OnReceived(object sender, NetReceivedEventArgs<byte[]> e)
//        {
//            if (DataReceived != null)
//            {
//                DataReceived(this, e.Data);
//            }
//        }

//        void server_OnReceived(object sender, NetClientReceivedEventArgs<byte[]> e)
//        {
//            if (DataReceived != null)
//            {
//                DataReceived(this, e.Data);
//            }
//        }

//        public void Bind(string address)
//        {
//            int idx = address.IndexOf(":");
//            int port = int.Parse(address.Substring(idx + 1));

//            server.Start(IPAddress.Parse(address.Substring(0,idx)), port);
//        }

//        public void Connect(string address)
//        {
//            int idx = address.IndexOf(":");
//            int port = int.Parse(address.Substring(idx + 1));

//            client.Connect(address.Substring(0, idx), port);
//        }

//        public void Send(byte[] data)
//        {
//            if (isServer)
//            {
//                Guid onlyClient = server.Clients[0];
//                server.ClientStreams[onlyClient].Send(data);
//            }
//            else
//            {
//                client.Send(data);
//            }
//        }

//        public void Dispose()
//        {
//            if (isServer)
//            {
//                server.DisconnectAll(); 
//                server.Stop();
//                server = null;                
//            }
//            else
//            {
//                client.Disconnect();
//                client = null;
//            }
//        }
//    }
//}
